package cheme.ProcessModel.Subprocess;

import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.Rectangle;

import cheme.ProcessModel.AbstractParent;
import cheme.ProcessModel.IModelElement;
import cheme.ProcessModel.IParent;
import cheme.ProcessModel.ITranslatable;
import cheme.ProcessModel.Visitors.IModelVisitor;


public class Subprocess extends AbstractParent<ITranslatable> implements ISubprocess
{
	/*
	 * Serialization version identifier. (Set to default for now)
	 */
	
	private static final long serialVersionUID = 1L;

	IParent parent;
	
	/*
	 * The geometry of the node.
	 */
	private Rectangle bounds;
	
	public Subprocess()
	{
		this(null);
	}
	
	public Subprocess(IModelElement parent)
	{
		super(parent);
		initializeBounds();
	}
		
	private void initializeBounds()
	{
		bounds = new Rectangle(10, 10, 200, 100);
	}
	
	public Rectangle getBounds()
	{
		return bounds.getCopy();
	}

	public void setBounds(Rectangle bounds)
	{
		if(!this.bounds.equals(bounds))
		{
			Rectangle oldBounds = new Rectangle(this.bounds);
			this.bounds = bounds;

			firePropertyChange(P_CONSTRAINT, oldBounds, bounds);
		}
	}
	
	public Point getLocation()
	{
		return bounds.getTopLeft();
	}
	
	public void setLocation(Point location)
	{
		bounds.setLocation(location);
		firePropertyChange(P_CONSTRAINT, null, bounds);
	}
	
	public Dimension getSize()
	{
		return new Dimension(50,50);
	}
	
	public void setSize(Dimension size)
	{
		bounds.setSize(size);
		firePropertyChange(P_CONSTRAINT, null, bounds);
	}
	
	public Object accept(IModelVisitor ruleChecker)
	{
		return ruleChecker.visit(this);
	}
}
